<?PHP
	// *******************************************************************************************
	// @Namespace : Top Level
	// @Description : Core File for Expression Framework
	// @Author : Ronald Guillen
	// *******************************************************************************************
	
	define("FRAMEWORK_PATH", "colibri-framework/");
	
	class Framework
	{
		function __construct()
		{
			// Not implemented
		}
		
		public function Import($classPath = "", $directoryPath = NULL)
		{
			if($directoryPath == NULL)
			{
				if(strpos($classPath, "*") != false || $classPath == "*")
				{
					$classDirectory = str_replace(".", "/", $classPath);
					$classDirectory = str_replace("*", "", $classDirectory);
					Framework::loadDirectory(FRAMEWORK_PATH.strtolower($classDirectory));
				}
				else
				{
					$classFile = str_replace(".", "/", $classPath).".php";
					Framework::loadFile(FRAMEWORK_PATH.strtolower($classFile));
				}
			}
			else
			{
				if(strpos($classPath, "*") != false || $classPath == "*")
				{
					$classDirectory = str_replace(".", "/", $classPath);
					$classDirectory = str_replace("*", "", $classDirectory);
					Framework::loadDirectory($directoryPath.strtolower($classDirectory));
				}
				else
				{
					$classFile = str_replace(".", "/", $classPath).".php";
					Framework::loadFile($directoryPath.strtolower($classFile));
				}
			}
		}
		
		// #Helpers
		
		private function loadFile($filePath)
		{
			if(file_exists($filePath))
			{
				require_once($filePath);
			}
			else
			{
				exit("The class <strong>".str_replace("/", ".", str_replace(FRAMEWORK_PATH, "", $filePath))."</strong> don't exists in the framework");
			}
		}
		
		private function loadDirectory($directory)
		{
			$handle = opendir($directory);
			
			while (( $file = readdir($handle) ) !== false)
			{
				if (preg_match("/^.*\.php$/i", $file) && !preg_match("/^.*\.php(4|5)\.inc$/i", $file))
				{
					require_once($directory.$file);
				}
			}
			
			closedir($handle);
		}

	}

?>